﻿<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <h4 class="text-danger text-center">请输入课程信息</h4>
        </div>
        <div class="modal-body text-center">
            <h6>*课程状态填0~2：0为已开课，1为未开课可选报，2为未开课不可选报*</h6>
            <div class="form-group">
                <label>课程名称 </label>
                <br>
                <input class="coursename text-center" type="text" class="form-control" aria-label="...">
            </div>
            <div class="form-group">
                <label>课程学分 </label>
                <br>
                <input class="coursecret text-center" type="text" class="form-control" aria-label="...">
            </div>
            <div class="form-group">
                <label>总课时</label>
                <br>
                <input class="coursetime text-center" type="text" class="form-control" aria-label="...">
            </div>
            <div class="form-group">
                <label>课程状态 </label>
                <br>
                <input class="coursetap text-center" type="text" class="form-control" aria-label="...">
            </div>
        </div>
        <div class="modal-footer">
            <a class="btn btn-primary" data-dismiss="modal">确认发布</a>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="text-danger">注意</h4>
            </div>
            <div class="modal-body">
                <h5>内容不能为空</h5>
            </div>
            <div class="modal-footer">
                <a class="btn btn-primary" data-dismiss="modal">确认</a>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="text-danger">提示</h4>
            </div>
            <div class="modal-body">
                <h5>课程发布成功</h5>
            </div>
            <div class="modal-footer">
                <a class="btn btn-primary" data-dismiss="modal">确认</a>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h4 class="text-danger">提示</h4>
                                </div>
                                <div class="modal-body">
                                    <h5>课程发布失败</h5>
                                </div>
                                <div class="modal-footer">
                                    <a class="btn btn-primary" data-dismiss="modal">确认</a>
                                </div>
                            </div>
                        </div>
                    </div>
<script>
    $('.btn-primary').click(function () {
        var coursename = $('.coursename').val()
        var coursecret = $('.coursecret').val()
        var coursetime = $('.coursetime').val()
        var coursetap = $('.coursetap').val()
        var obj = {
            cname: coursename,
            credit: Number(coursecret),
            chour: Number(coursetime),
            type: Number(coursetap)
        }
        console.log(coursename == '');
        if (coursename == '') {
            $('#myModal2').modal()
        }else if (coursecret == '') {
            $('#myModal2').modal()
        }else if (coursetime == '') {
            $('#myModal2').modal()
        }else if (coursetap == '') {
            $('#myModal2').modal()
        }else {
            $.ajax({
                url: '/add-course',
                type: 'POST',
                data: obj,
                success: function (data) {
                    if (data.status == 1) {
                        $('#myModal3').modal()
                    } else {
                        $('#myModal4').modal()
                    }
                },
                error: function (data) {
                    console.log('出错啦')
                }
            })
        }
    })
</script>
